package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.domain.DataCourseParamHistory;
import com.uwlaser.service.DataCourseParamHistoryService;
import com.uwlaser.service.dto.DataCourseParamHistoryDto;
import com.uwlaser.service.dto.DataCourseParamHistoryQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-11
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "过程数据-历史管理")
@RequestMapping("/api/dataCourseParamHistory")
public class DataCourseParamHistoryController {

    private final DataCourseParamHistoryService dataCourseParamHistoryService;

    @GetMapping
    @Log("查询过程数据-历史")
    @ApiOperation("查询过程数据-历史")
    @PreAuthorize("@el.check('dataCourseParamHistory:list')")
    public ResponseEntity query(DataCourseParamHistoryQueryParam query, Pageable pageable){
        return new ResponseEntity<>(dataCourseParamHistoryService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增过程数据-历史")
    @ApiOperation("新增过程数据-历史")
    @PreAuthorize("@el.check('dataCourseParamHistory:add')")
    public ResponseEntity create(@Validated @RequestBody DataCourseParamHistoryDto resources){
        return new ResponseEntity<>(dataCourseParamHistoryService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改过程数据-历史")
    @ApiOperation("修改过程数据-历史")
    @PreAuthorize("@el.check('dataCourseParamHistory:edit')")
    public ResponseEntity update(@Validated @RequestBody DataCourseParamHistoryDto resources){
        dataCourseParamHistoryService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除过程数据-历史")
    @ApiOperation("删除过程数据-历史")
    @PreAuthorize("@el.check('dataCourseParamHistory:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        dataCourseParamHistoryService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出过程数据-历史")
    @ApiOperation("导出过程数据-历史")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('dataCourseParamHistory:list')")
    public void download(HttpServletResponse response, DataCourseParamHistoryQueryParam query) throws IOException {
        dataCourseParamHistoryService.download(dataCourseParamHistoryService.queryAll(query), response);
    }*/

}
